package main

import (
	"fmt"
	"listExcel/conf"
	"listExcel/mui"
	server "listExcel/server"
	"os"
	"path/filepath"

	"github.com/andlabs/ui"
	_ "github.com/andlabs/ui/winmanifest"
	//	"runtime"
)

var mainwin *ui.Window

func main() {
	ROOT_PATH, err := filepath.Abs(filepath.Dir(os.Args[0]))
	if err != nil {
		panic(err)
	}
	// 从配置文件读取配置
	conf.Init(ROOT_PATH)
	os.Setenv("ROOT_PATH", ROOT_PATH)
	fmt.Println(os.Args)
	if len(os.Args) < 2 {
		ui.Main(setupUI)
	} else {
		excel_file := os.Args[1]
		os.Setenv("excel_file", excel_file)
		ui.Main(setupUI)
	}
	//	runtime.GOMAXPROCS(runtime.NumCPU() - 1)
}

func setupUI() {

	mainwin = ui.NewWindow("sumroads的excel工具", 640, 480, true)
	mainwin.OnClosing(func(*ui.Window) bool {
		ui.Quit()
		return true
	})
	mui.Mainwin = mainwin
	ui.OnShouldQuit(func() bool {
		mainwin.Destroy()
		return true
	})

	tab := ui.NewTab()
	mainwin.SetChild(tab)
	mainwin.SetMargined(true)
	mui.Mainwin = mainwin
	server.Mainwin = mainwin

	tab.Append("清洁excel", mui.MakeExcelPage(server.ClearExcel))
	tab.SetMargined(0, true)
	tab.Append("分类excel", mui.MakeExcelClassPage(server.HandleExcel))
	tab.SetMargined(1, true)
	/*
		tab.Append("Basic Controls", makeBasicControlsPage())
		tab.SetMargined(1, true)

		tab.Append("Numbers and Lists", makeNumbersPage())
		tab.SetMargined(2, true)

		tab.Append("Data Choosers", makeDataChoosersPage())
		tab.SetMargined(3, true)
	*/

	mainwin.Show()
}
